<template>
  <div id="app">
    <keep-alive exclude='JingYanZhi'>
      <router-view></router-view>
    </keep-alive>
    <tip></tip>
    <loading></loading>
  </div>
</template>

<script>
import Tip from 'components/common/Tip'
import Loading from 'components/common/Loading'
import RemoteDAO from 'common/RemoteDAO'
import sessionDAO from 'common/sessionDAO'
import {getUrlParam} from 'common/common.util'
export default {
  name: 'app',
  components: {
    Tip,  // 文本提示框
    Loading // loading弹窗
  },
  created () {
    this.init()
    // this.test()
  },
  methods: {
    init () {
      let mobile = this.$route.query.yyzmobile || getUrlParam('yyzmobile') || ''
      let nrngRegister = this.$route.query.nrngregister || getUrlParam('nrngregister') || ''
      let userCode = this.$route.query.usercode || getUrlParam('yyzusercode') || ''
      if (mobile === '') {
        this.$store.dispatch('setLoginStatus', true)
        this.changeShareUrl()
        return
      }
      if (nrngRegister === '1') {
        sessionDAO.setUserCode(userCode)
        this.changeShareUrl()
        this.$store.dispatch('setLoginStatus', true)
      } else if (nrngRegister === '0') {
        this.changeShareUrl()
        this.$store.dispatch('setLoginStatus', true)
      } else {
        if (userCode === '') {
          this.getUsercode()
        } else {
          this.getNrngRegister(userCode)
        }
      }
    },
    getUsercode () {
      RemoteDAO.callUC12000004().then(res => {
        this.getNrngRegister(res)
      }, err => {
        this.$store.dispatch('setTip', {text: err.message})
      })
    },
    getNrngRegister (userCode) {
      RemoteDAO.callUC12000104(userCode).then(res => {
        if (res.data.body[0].SYNC_SYSTEM === '23') {
          sessionDAO.setUserCode(userCode)
        }
        this.changeShareUrl()
        this.$store.dispatch('setLoginStatus', true)
      }, err => {
        this.$store.dispatch('setTip', {text: err.message})
      })
    },
    changeShareUrl () {
      document.getElementsByTagName('meta')['yyzshareurl']['content'] = 'http://dl.app.gtja.com/nrng/newShares/gldh-game-award.html?source=squarePage&usercode=' + sessionDAO.getUserCode()
    },
    test () {
      RemoteDAO.decodeUsercode().then(res => {
        console.log(res)
      }, err => {
        console.log(err)
      })
    }
  }
}
</script>
